package club.easin.sq.bl;

import club.easin.common.DatagridRequestDto;
import club.easin.pow.dto.UserSession;
import club.easin.sq.dao.SqFeedbackMapper;
import club.easin.sq.dto.SqFeedback;
import club.easin.utils.*;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.genid.GenId;

import javax.smartcardio.CommandAPDU;
import java.util.Date;

@Service("Feedbackbl")
public class Feedbackbl {

    @Autowired
    private SqFeedbackMapper sqFeedbackMapper;
    @Autowired
    private DBSubmit dbSubmit;


    public ReturnDto addFeedback(UserSession userSession, SqFeedback sqFeedback){
        Tlist tlist=new Tlist();
        sqFeedback.setBackid(Commutils.buildId());
        sqFeedback.setCreatetime(DateUtils.getNow());
        sqFeedback.setUpdatetime(DateUtils.getNow());
        sqFeedback.setBackuser(userSession.getUser().getUserid());
        tlist.add(SqFeedbackMapper.class,"insert",sqFeedback);
        dbSubmit.exce(tlist);
        return ReturnUtils.returnsuccess();
    }

    public ReturnDto editFeedack(UserSession userSession,SqFeedback sqFeedback){
        Tlist tlist=new Tlist();
        sqFeedback.setUpdatetime(DateUtils.getNow());
        tlist.add(SqFeedbackMapper.class,"updateByPrimaryKeySelective",sqFeedback);
        dbSubmit.exce(tlist);
        return ReturnUtils.returnsuccess();
    }

    public ReturnDto delFeedback(String backid){
        Tlist tlist=new Tlist();
        String[] ids=backid.split(",");
        for(String id:ids){
            tlist.add(SqFeedbackMapper.class,"deleteByPrimaryKey",id);
        }
        dbSubmit.exce(tlist);
        return ReturnUtils.returnsuccess();
    }

    public ReturnDto getFeedbackGrild(DatagridRequestDto dto){
        Page page=null;
        PageHelper.startPage(dto.getPagenum(),dto.getPagesize());
        page=sqFeedbackMapper.getFeedbackGrild();
        return ReturnUtils.returnsuccess(DataGrildUtils.returnDataGrild(page));
    }

    public ReturnDto getFeedbackByMaintainid(String maintainid){
        return ReturnUtils.returnsuccess(sqFeedbackMapper.getFeedListByManintainid(maintainid));
    }
}
